﻿namespace mVids
{
    using MediaPortal.ServiceImplementations;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class addManual : Form
    {
        private Button button1;
        private Button button2;
        private ComboBox comboBox1;
        private IContainer components = null;
        private Label label1;
        private Label label2;
        private ListBox listBox1;
        private string path;
        private TextBox textBox1;
        private TextBox textBox2;

        public addManual()
        {
            this.InitializeComponent();
        }

        private void addManual_Load(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bool flag;
            mVids.database database = new mVids.database();
            if (this.comboBox1.Items.Contains(this.textBox1.Text))
            {
                flag = false;
            }
            else
            {
                flag = true;
            }
            Log.Debug("Music Video DB - Manual Addition - artist={0}, isNew={1}, title={2}, file={3}", new object[] { this.textBox1.Text, flag.ToString(), this.textBox2.Text, this.path + this.listBox1.SelectedItem.ToString() });
            if (database.addManualFile(this.textBox1.Text, flag, this.textBox2.Text, this.path + this.listBox1.SelectedItem.ToString()))
            {
                MessageBox.Show("Successfully added file to Database!", "Done", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.listBox1.Items.RemoveAt(this.listBox1.SelectedIndex);
                this.textBox1.Text = "";
                this.textBox2.Text = "";
            }
            else
            {
                MessageBox.Show("Error adding file to Database!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.textBox1.Text = this.comboBox1.SelectedItem.ToString();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.textBox1 = new TextBox();
            this.listBox1 = new ListBox();
            this.comboBox1 = new ComboBox();
            this.label1 = new Label();
            this.textBox2 = new TextBox();
            this.label2 = new Label();
            this.button1 = new Button();
            this.button2 = new Button();
            base.SuspendLayout();
            this.textBox1.Location = new Point(0x1eb, 0x47);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new Size(0xb5, 20);
            this.textBox1.TabIndex = 0;
            this.listBox1.FormattingEnabled = true;
            this.listBox1.HorizontalScrollbar = true;
            this.listBox1.Location = new Point(10, 9);
            this.listBox1.Name = "listBox1";
            this.listBox1.Size = new Size(0x1db, 0xc7);
            this.listBox1.TabIndex = 1;
            this.listBox1.SelectedIndexChanged += new EventHandler(this.listBox1_SelectedIndexChanged);
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Location = new Point(0x1eb, 11);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new Size(0xb5, 0x15);
            this.comboBox1.TabIndex = 2;
            this.comboBox1.SelectedIndexChanged += new EventHandler(this.comboBox1_SelectedIndexChanged);
            this.label1.AutoSize = true;
            this.label1.Location = new Point(510, 0x27);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x90, 0x1a);
            this.label1.TabIndex = 3;
            this.label1.Text = "Choose an existing Artist \r\nor enter the new name below";
            this.label1.TextAlign = ContentAlignment.MiddleCenter;
            this.textBox2.Location = new Point(0x20f, 0x7b);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new Size(0x91, 20);
            this.textBox2.TabIndex = 4;
            this.label2.AutoSize = true;
            this.label2.Location = new Point(0x1eb, 0x7e);
            this.label2.Name = "label2";
            this.label2.Size = new Size(30, 13);
            this.label2.TabIndex = 5;
            this.label2.Text = "Title:";
            this.button1.Location = new Point(0x1f8, 0xb8);
            this.button1.Name = "button1";
            this.button1.Size = new Size(0x4b, 0x17);
            this.button1.TabIndex = 6;
            this.button1.Text = "Add";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new EventHandler(this.button1_Click);
            this.button2.Location = new Point(0x255, 0xb8);
            this.button2.Name = "button2";
            this.button2.Size = new Size(0x4b, 0x17);
            this.button2.TabIndex = 7;
            this.button2.Text = "Close";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new EventHandler(this.button2_Click);
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x2a6, 0xdb);
            base.Controls.Add(this.button2);
            base.Controls.Add(this.button1);
            base.Controls.Add(this.label2);
            base.Controls.Add(this.textBox2);
            base.Controls.Add(this.label1);
            base.Controls.Add(this.comboBox1);
            base.Controls.Add(this.listBox1);
            base.Controls.Add(this.textBox1);
            base.Name = "addManual";
            this.Text = "addManual";
            base.Load += new EventHandler(this.addManual_Load);
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (((this.listBox1.SelectedIndex >= 0) && (this.listBox1.SelectedIndex < this.listBox1.Items.Count)) && this.listBox1.SelectedItem.ToString().Contains("-"))
            {
                string[] strArray = this.listBox1.SelectedItem.ToString().Split("-".ToCharArray());
                this.textBox2.Text = strArray[1].Trim();
                this.textBox1.Text = strArray[0].Trim();
            }
        }

        public void setupWindow(List<string> files, List<string> filesinDB, List<string> artistsinDB)
        {
            foreach (string str in files)
            {
                if (!filesinDB.Contains(str))
                {
                    this.listBox1.Items.Add(str);
                }
            }
            this.comboBox1.Items.AddRange(artistsinDB.ToArray());
        }
    }
}

